﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace UeyesAIS.DataDefinition
{
    [XmlType(TypeName = "配置文件")]
    public class APICommand
    {
        private List<PowerOnCmd> _poweroncmd;
        [XmlElement]
        public CorrectCmd Correct { get; set; }
        [XmlElement]
        public DustCmd Dust { get; set; }
        [XmlElement]
        public VisiualCmd Visiual { get; set; }
        [XmlArray("电测图列表")]
        public List<PowerOnCmd> Poweron
        {
            get
            {
                if (_poweroncmd == null)
                    _poweroncmd = new List<PowerOnCmd>();
                return _poweroncmd;
            }
            set
            {
                _poweroncmd = value;
            }
        }
        public int GetNeeds()
        {
            int count = 0;
            if (Dust != null && Dust.Dustlist != null)
                count += Dust.Dustlist.Count;
            if (Visiual != null && Visiual.VisEnable == 1)
                count++;
            if (Poweron != null)
                Poweron.ForEach(x =>
                    {
                        if (x.NeedInsp == 0)
                            count++;
                    });
            return count;
        }
        internal PicSize imagesize { get; set; }
        internal object GetNeeds(int i)
        {
            return i;
        }
    }
    [XmlType(TypeName = "校正项")]
    public class CorrectCmd : BaseInfo
    {
        /// <summary>
        /// 校正方式0-边框校正，1-RGB校正，2-白点图校正
        /// </summary>
        [XmlAttribute]
        public double CorrIndex { get; set; }
    }
    [XmlType(TypeName = "除尘项")]
    public class DustCmd
    {
        private List<BaseInfo> _baseinfo;
        /// <summary>
        /// 清灰图列表
        /// </summary>
        [XmlArray("灰尘参数")]
        public List<BaseInfo> Dustlist
        {
            get
            {
                if (_baseinfo == null)
                    _baseinfo = new List<BaseInfo>();
                return _baseinfo;
            }
            set
            {
                _baseinfo = value;
            }
        }
    }
    [XmlType(TypeName = "目测项")]
    public class VisiualCmd : BaseInfo
    {
        /// <summary>
        /// 是否目测0-不启用目测，1-启用
        /// </summary>
        [XmlAttribute]
        public double VisEnable { get; set; }
    }
    [XmlType(TypeName = "电测项")]
    public class PowerOnCmd : BaseInfo
    {
        /// <summary>
        /// 是否检测0-检测，1-不检
        /// </summary>
        [XmlAttribute]
        public double NeedInsp { get; set; }
        /// <summary>
        /// 切图时间
        /// </summary>
        [XmlAttribute]
        public double ChangTime { get; set; }
    }
    [XmlType(TypeName = "基类项")]
    public class BaseInfo
    {
        /// <summary>
        /// 曝光时间
        /// </summary>
        [XmlAttribute]
        public double CorrExporsetime { get; set; }
        /// <summary>
        /// 拍图延迟时间
        /// </summary>
        [XmlAttribute]
        public double CorrDelaytime { get; set; }
        /// <summary>
        /// 图片索引
        /// </summary>
        [XmlAttribute]
        public double Picindex { get; set; }
        /// <summary>
        /// 光源亮度
        /// </summary>
        [XmlAttribute]
        public double Intensity { get; set; }
    }
    public class PicSize
    {
        public int LCDWidth { get; set; }
        public int LCDHeight { get; set; }
        public int LCDPixelType { get; set; }

    }
}
